package com.itrip.itripbiz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itrip.common.DtoUtil;
import com.itrip.common.EmptyUtils;
import com.itrip.common.ErrorCode;
import com.itrip.dto.Dto;
import com.itrip.entity.*;
import com.itrip.service.*;
import com.itrip.vo.ItripAreaDicVO;
import com.itrip.vo.ItripLabelDicVO;
import com.itrip.vo.hotel.HotelVideoDescVO;
import com.itrip.vo.hotel.ItripSearchDetailsHotelVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/biz/api")
public class HotelController {

    @Resource
    private ItripHotelService itripHotelService;
    @Resource
    private ItripLabelDicService itripLabelDicService;
    @Resource
    private ItripAreaDicService itripAreaDicService;
    //查询酒店政策
    @GetMapping("/hotel/queryhotelpolicy/{cityId}")
    public Dto ListItripDicVoId(@PathVariable("cityId") Long id){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("id",id);
        //只要查询哪些字段
        qw.select("hotelPolicy");
        ItripHotel one = itripHotelService.getOne(qw);
        return DtoUtil.returnDataSuccess(one.getHotelPolicy());
    }
    //查询酒店设施
    @GetMapping("/hotel/queryhotelfacilities/{cityId}")
    public Dto<ItripHotel> itripHoteldto(@PathVariable("cityId") Long id){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("id",id);
        qw.select("facilities");
        ItripHotel itripHotel = itripHotelService.getOne(qw);
        return DtoUtil.returnDataSuccess(itripHotel.getFacilities());
    }
    //查询酒店视频信息
    @GetMapping("hotel/getvideodesc/{cityid}")
    public Dto<HotelVideoDescVO> chaxunjiudian(@PathVariable Long cityid){
        HotelVideoDescVO itripHotel=new HotelVideoDescVO();
        if(EmptyUtils.isNotEmpty(cityid)){
            itripHotel=itripHotelService.chaxunjuedian(cityid);
            if(EmptyUtils.isNotEmpty(itripHotel)){
                return DtoUtil.returnSuccess("查询成功",itripHotel);
            }else{
                return DtoUtil.returnSuccess("itripHotel值为空",ErrorCode.AUTH_PARAMETER_ERROR);
            }
        }
        return DtoUtil.returnDataSuccess(itripHotel);
    }
    //查询所有酒店特色
    @GetMapping("/hotel/queryhoteldetails/{cityid}")
    public Dto<ItripSearchDetailsHotelVO> tesejieshao(@PathVariable("cityid") Long cityid){
        List<ItripSearchDetailsHotelVO> itsitSearch=itripHotelService.itrip(cityid);
        if(EmptyUtils.isNotEmpty(itsitSearch)){
            return DtoUtil.returnSuccess("查询成功",itsitSearch);
        }else{
            return DtoUtil.returnSuccess("itripSearchDetailsHotelVO值为空",ErrorCode.AUTH_PARAMETER_ERROR);
        }
    }


    @GetMapping("/hotel/queryhotelfeature")
    public Dto<ItripLabelDicVO> itripLabelDicVODto(){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("parentId",16);
        qw.select("description","id","name","pic");
        List<ItripLabelDic>itripLabelDic = itripLabelDicService.list(qw);
        return DtoUtil.returnDataSuccess(itripLabelDic);
    }

    //查询城市商圈
    @GetMapping("/hotel/querytradearea/{cityId}")
    public Dto<ItripAreaDic> itripAreaDicDto(@PathVariable("cityId") Long id){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("parent",id);
        qw.eq("isTradingArea",1);
        qw.select("id","name");
        List<ItripAreaDicVO> itripAreaDicVOS = itripAreaDicService.list(qw);
        return DtoUtil.returnDataSuccess(itripAreaDicVOS);
    }

    @GetMapping("/hotel/queryhotcity/{cityid}")
    public Dto<ItripAreaDicVO> aredToHop(@PathVariable Integer cityid) {
        List<ItripAreaDic> itripAreaDics = null;
        List<ItripAreaDicVO> itripAreaDicVOS = null;
        try {
            if (EmptyUtils.isNotEmpty(cityid)) {

                Map map = new HashMap();
                map.put("isHot", 1);
                map.put("isChina", cityid);
                itripAreaDics = itripAreaDicService.areaDicSelect(map);
                if (EmptyUtils.isNotEmpty(itripAreaDics)) {
                    itripAreaDicVOS = new ArrayList<>();
                    for (ItripAreaDic itripAreaDic : itripAreaDics) {
                        ItripAreaDicVO itripAreaDicVO = new ItripAreaDicVO();
                        BeanUtils.copyProperties(itripAreaDic, itripAreaDicVO);
                        itripAreaDicVOS.add(itripAreaDicVO);
                    }
                }
            }else {
                DtoUtil.returnFail("cityid不能为空", ErrorCode.AUTH_ILLEGAL_USERCODE);
            }
        }catch (Exception e){
            e.printStackTrace();
            DtoUtil.returnFail("cvdgf",ErrorCode.AUTH_PARAMETER_ERROR);

        }
        return DtoUtil.returnDataSuccess(itripAreaDicVOS);
    }

}
